using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cmc.Modbus.Base
{
    public class ReadData
    {
        public string Ip { get; set; }

        public int Port { get; set; } = 502;

        public int Id { get; set; } = 0;

        /// <summary>
        /// 端口号
        /// </summary>
        public byte StationNumber { get; set; } = 0x01;
        public CommunicationType CommunicationType { get; set; } = CommunicationType.TcpClient;

        public FunctionType FunctionType { get; set; }

        public ModbusCmdType ModbusCmdType { get; set; }

        /// <summary>
        /// 写入对应地址值
        /// </summary>
        public List<AddressRead> ReadAddresses = new List<AddressRead>();

        public int StartAddress
        {
            get
            {
               return   ReadAddresses.Select(m=>m.Address).Min() ;
            }
        }
        /// <summary>
        /// 读取长度
        /// </summary>
        public int Length
        {
            get
            {
                return  ReadAddresses.Select(m => m.Address).Max()-ReadAddresses.Select(m=>m.Address).Min()+1;
            }
        }

        public object Server { get; set; }

    }
}
